package com.yheriatovych.reductor.example.model;

/**
 * 用来记录一个操作节点
 *
 * @since 2021-05-06
 */
public class Note {
    /**
     * 节点的ID
     */
    private final int id;

    /**
     * 显示内容
     */
    private final String note;

    /**
     * 是否选中
     */
    private final boolean isChecked;

    /**
     * 构造方法
     *
     * @param id
     * @param note
     * @param isChecked
     */
    public Note(int id, String note, boolean isChecked) {
        this.id = id;
        this.note = note;
        this.isChecked = isChecked;
    }

    @Override
    public String toString() {
        return String.format("[" + (isChecked ? "+" : " ") + "] " + note);
    }

    @Override
    public boolean equals(Object object) {
        if (this == object) {
            return true;
        }
        if (object == null || getClass() != object.getClass()) {
            return false;
        }

        Note note1 = (Note) object;

        if (id != note1.id) {
            return false;
        }
        if (isChecked != note1.isChecked()) {
            return false;
        }
        return note != null ? note.equals(note1.getNote()) : note1.getNote() == null;
    }

    public int getId() {
        return id;
    }

    public String getNote() {
        return note;
    }

    /**
     * isChecked
     *
     * @return
     */
    public boolean isChecked() {
        return isChecked;
    }

    @Override
    public int hashCode() {
        int result = id;
        result = 31 * result + (note != null ? note.hashCode() : 0);
        result = 31 * result + (isChecked ? 1 : 0);
        return result;
    }
}
